package com.ibeeking.found.org.cp.rest.controller.v1;

import com.ibeeking.found.common.db.annotation.Read;
import com.ibeeking.found.common.utils.UserUtils;
import com.ibeeking.found.org.cp.rest.service.IEmployeeAddressService;
import com.ibeeking.found.org.service.common.param.EmployeeAddressParam;
import com.ibeeking.found.org.service.common.vo.EmployeeAddressListVO;
import com.ibeeking.found.org.service.common.vo.EmployeeAddressVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ReceAddrController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-01-27 18:50
 **/
@RestController
@RequestMapping("/cp/address/v1")
public class EmployeeAddressController {

    @Resource
    private IEmployeeAddressService addressServiceImpl;

    @Read
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "会员收货地址分页列表")
    @PostMapping(value = "/list")
    public List<EmployeeAddressListVO> list() {
        return addressServiceImpl.list(UserUtils.getUserId());
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "地址添加")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) EmployeeAddressParam param) {
        return addressServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "地址修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) EmployeeAddressParam param) {
        return addressServiceImpl.modify(param);
    }

    @Read
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "地址详情")
    @PostMapping(value = "/view/{id}")
    public EmployeeAddressVO view(@PathVariable("id") Long id) {
        return addressServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "地址删除")
    @PostMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return addressServiceImpl.del(id);
    }
}
